package com.xinqi.modules.exam.student.controller.admin;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.exam.student.dto.req.CourseExamPaperStudentCreateDTO;
import com.xinqi.modules.exam.student.dto.req.CourseExamPaperStudentQueryDTO;
import com.xinqi.modules.exam.student.dto.req.CourseExamPaperStudentUpdateDTO;
import com.xinqi.modules.exam.student.dto.rsp.CourseExamPaperStudentResultDTO;
import com.xinqi.modules.exam.student.service.CourseExamPaperStudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 课程测评学生答题Admin控制层
 *
 * @author: linkai
 * @date: 2023/07/02
 */
@Tag(name = "Admin-课程测评学生答题", description = "课程测评学生答题Admin接口")
//@RestController
@RequestMapping("/admin/exam-paper/student")
@RequiredArgsConstructor
public class CourseExamPaperStudentAdminController {
    private final CourseExamPaperStudentService courseExamPaperStudentService;

    /**
     * 课程测评学生答题-分页
     */
    @Operation(summary = "课程测评学生答题-分页")
    @GetMapping("/page")
    public R<PageInfo<CourseExamPaperStudentResultDTO>> page(@ParameterObject CourseExamPaperStudentQueryDTO dto) {
        PageInfo<CourseExamPaperStudentResultDTO> page = courseExamPaperStudentService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 课程测评学生答题-详情
     */
    @Operation(summary = "课程测评学生答题-详情")
    @GetMapping("/{id}")
    public R<CourseExamPaperStudentResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        CourseExamPaperStudentResultDTO dto = courseExamPaperStudentService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增课程测评学生答题
     */
    @Operation(summary = "新增课程测评学生答题")
    @PostMapping
    public R<Long> insert(@RequestBody CourseExamPaperStudentCreateDTO dto) {
        return R.data(courseExamPaperStudentService.insert(dto));
    }

    /**
     * 修改课程测评学生答题
     */
    @Operation(summary = "修改课程测评学生答题")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id,
                             @RequestBody CourseExamPaperStudentUpdateDTO dto) {
        dto.setId(id);
        return R.data(courseExamPaperStudentService.updateById(dto));
    }

    /**
     * 删除课程测评学生答题
     */
    @Operation(summary = "删除课程测评学生答题")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(courseExamPaperStudentService.deleteById(id));
    }
}
